package six

import org.apache.spark.{SparkConf, SparkContext}

import scala.collection.mutable.ListBuffer

object MapPartitionsWithIndexTestScala {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("TestTransformation").setMaster("local")
    val sc = new SparkContext(conf)

    val list = List(1, 2, 3, 4, 5, 6, 7, 8)
    val listRDD = sc.parallelize(list)

    listRDD.mapPartitionsWithIndex((index, iterator) => {
      val listBuffer: ListBuffer[String] = new ListBuffer

      while (iterator.hasNext) {
        listBuffer.append(index + "+" + iterator.next())
      }
      listBuffer.iterator
    }, true).foreach(println(_))
  }
}
